//
//  TF_CourseDownloadCell.swift
//  TalkfunSDKDemo
//
//  Created by 邓盛明 on 2022/2/22.
//  Copyright © 2022 Talkfun. All rights reserved.
//

import UIKit

class TF_CourseDownloadCell: UITableViewCell {
    var courseImg:UIImageView!
    var imgType:UILabel!  //pdf还是PDf
    var courseTitle:UILabel!  //题目
    var coursePage:UILabel!  //页数
    var courseTotal:UILabel!  //大小
    @objc public let controlBtn = TalkfunIncreaseButton()//下载按钮变化
    @objc public  var cellwidth:CGFloat = 0
    var lineView:UIView!
    var maskLayer:CAShapeLayer!
    @objc public var type:ClassLive = .small
    @objc public let downloadBtnLabel = UILabel() //下载状态 (已暂停 下载中  播放)

    var progressView:UIView!//进度条
    var progressViewLine:UIView!
    var progressLab:UILabel!
    var dataArr:NSMutableArray = NSMutableArray.init()
    @objc public var IDs:Int = 0   //识别ID
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.courseImg = UIImageView.init()
        self.contentView.addSubview(self.courseImg);
        
        self.imgType = UILabel.init()
        self.imgType.text = "pdf";
        self.imgType.font = UIFont.PingFang(size: 14)
        self.imgType.textColor = UIColor.white
        self.imgType.textAlignment = .center
        self.courseImg.addSubview(self.imgType)
       
        
        self.courseTitle = UILabel.init()
        self.courseTitle.text = "建筑空间曲线";
        self.courseTitle.font = UIFont.PingFang(size: 12)
        
        self.contentView.addSubview(self.courseTitle)
        
        self.coursePage = UILabel.init()
        self.coursePage.text = "页数:4页(共25)";
        self.coursePage.font = UIFont.PingFang(size: 12)
        self.contentView.addSubview(self.coursePage)
        
        self.courseTotal = UILabel.init()
        self.courseTotal.text = "大小:53.3M";
        self.courseTotal.font = UIFont.PingFang(size: 12)
       
        self.contentView.addSubview(self.courseTotal)
        
        self.controlBtn.setImage(UIImage.init(named: "HTLive.bundle/CoursewareNotStarted"), for: UIControl.State.normal)
               
        self.controlBtn.titleLabel?.font = UIFont.PingFang(size: 12)
        self.contentView.addSubview(self.controlBtn)
        
        self.downloadBtnLabel.text = "下载失败";
        self.downloadBtnLabel.textColor = UIColor(red: 0.94, green: 0.25, blue: 0.25,alpha:1)
        self.downloadBtnLabel.font = UIFont.PingFang(size: 12)
        self.contentView.addSubview(self.downloadBtnLabel)
        self.downloadBtnLabel.isHidden = true
        
        self.lineView = UIView.init()
        self.lineView.backgroundColor = UIColor(red: 220/255.0, green: 228/255.0, blue: 235/255.0, alpha: 1.0)
        self.contentView.addSubview(self.lineView)
        
        self.progressViewLine = UIView.init()
        self.progressViewLine.backgroundColor = UIColor(red: 0.35, green: 0.4, blue: 0.44, alpha: 1)
        self.progressViewLine.isHidden = true
        self.contentView.addSubview(self.progressViewLine);
        
        self.progressView = UIView.init()
        
        self.progressViewLine.addSubview(self.progressView)
        
        self.progressLab = UILabel.init()
        self.progressLab.text = "75%";
        self.progressLab.textColor = UIColor(red: 0.25, green: 0.59, blue: 0.92,alpha:1)
        self.progressLab.isHidden = true
        self.progressLab.font = UIFont.PingFang(size: 10)
        self.contentView.addSubview(self.progressLab)
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        self.lineView.frame = CGRect(x: 0, y: self.frame.size.height-1, width: self.cellwidth, height: 1)
        self.controlBtn.frame = CGRect(x: self.cellwidth-57, y: (self.frame.size.height-36)/2.0, width:36, height:36)
        self.downloadBtnLabel.frame = CGRect(x: self.cellwidth-65, y: self.controlBtn.frame.maxY, width: 50, height: 16.5)
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
        
        
    }
    

    func StringToFloat(str:String)->(CGFloat){


            let string = str

            var cgFloat:CGFloat = 0

            if let doubleValue = Double(string)

            {

                cgFloat = CGFloat(doubleValue)

            }

            return cgFloat

     }
    

    
    func getMaskLayer(rect:CGRect) {
        if self.maskLayer == nil {
            let size = CGSize(width: 2, height: 2)
            let maskPath = UIBezierPath.init(roundedRect: rect, byRoundingCorners: [.bottomRight], cornerRadii: size)
            let maskLayer = CAShapeLayer.init()
            maskLayer.frame = rect
            maskLayer.path = maskPath.cgPath
            self.maskLayer = maskLayer
        }
     }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}

